package DTO;

import database.DatabaseHelper;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;

public class ArticleDTO {
	private String article;
	private String name;
	
	//Property Article
	public String getArticle() { return article; }
	public void setArticle(String article) { this.article = article; }
	
	//Property Article Name
	public String getName() { return name; }
	public void setName(String name) { this.name = name; }
	
	public static ArticleDTO getArticle(Context context, String article){
		ArticleDTO result = new ArticleDTO();
		DatabaseHelper myDbHelper = DatabaseHelper.getInstance(context);

	 	try {
	 		myDbHelper.openDatabase();
	 	}catch(SQLException sqle){
	 		throw sqle;
	 	}
		
	 	String query = "SELECT * FROM Articles WHERE Article = '" + article + "'";
	 	Cursor cursor = null;
	 	try{
	 		cursor =myDbHelper.getMyDataBase().rawQuery(query, null);
	 	}catch(Exception e){
	 		
	 	}
	 	if(cursor.moveToFirst()){
	 		result.setArticle(cursor.getString(cursor.getColumnIndex("Article")));
	 		result.setName(cursor.getString(cursor.getColumnIndex("Name")));
	 	}
	 	myDbHelper.close();
		return result;
	}
}
